package org.example.ch16;

/**
 * https://leetcode-cn.com/problems/reverse-bits/
 * 颠倒给定的 32 位无符号整数的二进制位。
 */
public class ReverseBits {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        int rev = 0;
        for (int i = 0; i < 32 && n!=0; i++) {
            rev |= (n & 1) << (31-i);
            n >>>= 1;
        }
        return rev;
    }
}
